layui.use(["table", "form"], function () {
    var $ = layui.jquery;
    var table = layui.table;
    var form = layui.form;

    var BusinessHandle = {
        tableId: "businessResultTable",    //表格id
        condition: {
            accountId: "",
            jobId: ""
        }
    };

    BusinessHandle.initColumn = function () {
        return [[
            {field: 'jobStatus', align: "center", title: '任务状态'},
            {field: 'resultType', align: "center", title: '号码类型'},
            {field: 'resultId', align: "center", title: '办理号码'},
            {field: 'status', align: "center", title: '查询状态(0-成功，非0-失败)'},
            {field: 'message', align: "center", title: '错误信息'}
        ]];
    };

    table.render({
        elem: '#' + BusinessHandle.tableId,
        url: Feng.ctxPath + '/businessHandle/queryHandleResult',
        page: true,
        limit: 20,
        limits: [20],
        height: "full-98",
        cellMinWidth: 100,
        cols: BusinessHandle.initColumn()
    });

    function initAccountSelect(accountId) {
        $('#accountId').html('');
        $("#accountId").append('<option value="">请选择</option>');
        $.ajax({
            dataType: 'json',
            type: 'post',
            url: Feng.ctxPath + "/account/allSelectAccounts",
            success: function (data) {
                for (var i = 0; i < data.data.length; i++) {
                    var name = data.data[i].accountName;
                    var code = data.data[i].accountId;
                    if (accountId == code) {
                        $("#accountId").append('<option value="' + code + '" selected>' + name + '</option>');
                    } else {
                        $("#accountId").append('<option value="' + code + '">' + name + '</option>');
                    }
                }
                form.render('select');
            }
        });
    };
    initAccountSelect();

    $("#btnSearch").click(function () {
        var accountId = $("#accountId").val();
        var jobId = $("#jobId").val();
        if ("" == accountId) {
            Feng.error("请选择一个集团信息查询账号！");
            return;
        }
        if ("" == jobId) {
            Feng.error("请输入需要查询的jobId!");
            return;
        }
        BusinessHandle.search();
    });

    BusinessHandle.search = function () {
        var queryData = {};
        queryData['accountId'] = $("#accountId").val();
        queryData['jobId'] = $("#jobId").val();
        table.reload(BusinessHandle.tableId, {
            where: queryData, page: {curr: 1}
        });
    };
});